import { Component, OnInit, OnDestroy } from '@angular/core';
import { NavParams } from '@ionic/angular';
import { DataService } from '@services/data.service';
import { CacheService } from '@services/cache.service';
import { ActivatedRoute } from '@angular/router';

@Component({
  selector: 'fire-link',
  templateUrl: 'fire-link.html',
  styleUrls: ['fire-link.scss']
})
export class FireKagePage implements OnInit, OnDestroy {
  alarms;                // 获取消防联动故障点数据
  typeData;              // 获取消防联动基础数据
  projectId;             // 项目ID
  constructor(
    // public navParams: NavParams,
    public activatedRoute: ActivatedRoute,
    public dataService: DataService,
    public cacheService: CacheService
  ) {
    this.projectId = this.cacheService.currentProject.projectId ? this.cacheService.currentProject.projectId : 0;
    this.getFireLink(this.projectId);
  }

  ngOnInit() {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad DevicePage');
  }

  /**
   * 获取消防联动数据
   * @param projecetId
   */

  getFireLink(projecetId) {
    this.dataService.getFireDevices(projecetId, 2).subscribe(res => {
      this.typeData = res.data.deviceRealTimeDetailsInfo;
      this.alarms = res.data.faultAlarmInfos;
      for (let i = 0; i < this.alarms.length; i++) {
        for (let j = 0; j < this.alarms[i].messages.length; j++) {
          this.alarms[i].messages[j].dateTime =
            this.alarms[i].messages[j].dateTime.substr(0, this.alarms[i].messages[j].dateTime.length - 4);
        }
      }
    });
  }

  ngOnDestroy() {
  }
}
